package com.googlecode.frameworksintegration.action;

import java.util.List;

import com.googlecode.frameworksintegration.dao.BlogDAO;
import com.googlecode.frameworksintegration.dao.BlogDAOImpl;
import com.googlecode.frameworksintegration.domain.Blog;
import com.opensymphony.xwork2.ActionSupport;

/**
 * Struts 2 Integrated with Hibernate 3 blogging example.
 * http://java.searchdaily.net
 * @author namnvhue
 * 
 */
public class BlogAction extends ActionSupport {
	private BlogDAO blogDAO = null;
	private List<Blog> blogs;
	private Blog blog;
	private String message;
	private String blogId;

	/**
	 * 
	 */
	public BlogAction() {
		this.blogDAO = new BlogDAOImpl();
	}

	private static final long serialVersionUID = -4901097198092626247L;

	public String listBlog() {
		this.blogs = blogDAO.listBlogs();

		return SUCCESS;
	}

	public String manageBlog() {
		this.blogs = blogDAO.listBlogs();

		return SUCCESS;
	}

	public String renderAddBlog() {
		this.blog = new Blog();
		return SUCCESS;
	}

	public String addBlog() {
		blogDAO.save(this.blog);
		this.message = "Blog has been created successfully.";
		return SUCCESS;
	}

	public String deleteBlog() {
		this.blog = this.blogDAO.find(Integer.parseInt(blogId));
		this.blogDAO.delete(blog);
		this.message = "Blog has been removed successfully.";
		return SUCCESS;
	}

	public String editBlog() {
		return SUCCESS;
	}

	public String detail(String id) {
		return SUCCESS;
	}

	public List<Blog> getBlogs() {
		return blogs;
	}

	public void setBlogs(List<Blog> blogs) {
		this.blogs = blogs;
	}

	public Blog getBlog() {
		return blog;
	}

	public void setBlog(Blog blog) {
		this.blog = blog;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getBlogId() {
		return blogId;
	}

	public void setBlogId(String blogId) {
		this.blogId = blogId;
	}

}
